import logging
import os


# 确保日志目录存在
LOG_DIR = "logs"
if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

# 配置日志
logging.basicConfig(
    level=getattr(logging, "DEBUG", logging.DEBUG),
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    handlers=[
        # 输出到文件
        logging.FileHandler(os.path.join(LOG_DIR, "app.log")),
        # 输出到控制台
        logging.StreamHandler(),
    ],
)

# 创建日志实例
logger = logging.getLogger("app")


def get_logger(name):
    """获取指定名称的日志实例"""
    return logging.getLogger(name)
